package edu.ynu.se.xiecheng.achitectureclass.controller;

import edu.ynu.se.xiecheng.achitectureclass.common.controller.LogicController;
import edu.ynu.se.xiecheng.achitectureclass.dao.DeviceDao;
import edu.ynu.se.xiecheng.achitectureclass.dto.DeviceDataDTO;
import edu.ynu.se.xiecheng.achitectureclass.entity.Device;
import edu.ynu.se.xiecheng.achitectureclass.service.DeviceService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;
import java.util.List;

@Api(tags = "设备实体的控制器")
@RestController
@RequestMapping("/devices")
public class DevicesController extends LogicController<DeviceService, DeviceDao, Device,Long> {
    public DevicesController(DeviceService service) { super(service);}

    @ApiOperation("获取最近的设备数据")
    @GetMapping("/getLatestDevicesData")
    public List<DeviceDataDTO> getLatestDevicesData(){
        return service.getLatestDevicesData();
    }

    @ApiOperation("获取最新的设备数据")
    @GetMapping("/getNewestDevicesData")
    public List<DeviceDataDTO> getNewestDevicesData(){
        service.getDevicesData();
        return service.getLatestDevicesData();
    }

    @ApiOperation("拍摄图片")
    @GetMapping("/capture")
    public String capturePhoto() throws IOException {
        return service.getNewCameraPhoto();
    }

}
